package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.GoodsGiftDao;
import com.yazi.mxz.common.entity.beans.GoodsGift;
import com.yazi.mxz.common.entity.beans.GoodsGiftId;
import com.yazi.mxz.common.entity.enums.GoodsGiftType;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("goodsGiftDao")
public class GoodsGiftDaoImpl extends BasicDao<GoodsGift> implements GoodsGiftDao {


	public GoodsGiftDaoImpl() {
		super(GoodsGift.class);
		
	}

	@Override
	public Criteria getExample(GoodsGift gg, String searchWord) {
		Criteria c = super.getExample(gg, searchWord);
		
		// 关联对象条件
		if (null != gg) {
			// ID
			GoodsGiftId id = gg.getId();
			if (null != id) {
				if (null != id.getSellId()) {
					c.add(Restrictions.eq("id.sellId", id.getSellId()));
				}
				if (null != id.getGiftId()) {
					c.add(Restrictions.eq("id.giftId", id.getGiftId()));
				}
				if (null != id.getType()) {
					c.add(Restrictions.eq("id.type", id.getType()));
				}
			}
			// ...其它关联对象条件
		}
		
		// ...关键字searchWord条件
		
		return c;
	}

	@Override
	public int deleteBySellId(long sellId, GoodsGiftType type) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("sellId", sellId);
		param.put("type", type.ordinal());
		return executeUpdate("delBySellIdHql", param);
	}

}
